package com.ourteam.product.requirement.dao.impl;

import com.ourteam.product.requirement.dao.IProductGlossaryRelateDAO;
import com.ourteam.product.requirement.dao.ProductGlossaryRelate;
import com.ourteam.product.requirement.dao.ProductGlossaryRelateDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-05-03 16:45:42
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductGlossaryRelateDAOJdbcImpl extends AbstractSpringDAO
    implements IProductGlossaryRelateDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, ProductDefineId, ProductGlossaryId, RelatedProductGlossaryId,
            RelatedType, Status, Remarks, RelatedName, RelatedGlossaryCode,
            RelatedGlossaryName
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.ProductDefineId,
            _DataObjectProperty.ProductGlossaryId,
            _DataObjectProperty.RelatedProductGlossaryId,
            _DataObjectProperty.RelatedType, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks, _DataObjectProperty.RelatedName,
            _DataObjectProperty.RelatedGlossaryCode,
            _DataObjectProperty.RelatedGlossaryName
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductGlossaryRelate, ProductGlossaryRelateDAOQueryBean> daoHelper;

    public AbstractProductGlossaryRelateDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductGlossaryRelate, ProductGlossaryRelateDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.product.requirement.dao.IProductGlossaryDAO.EntityName)
                                .append(" RELATED_VHNKKO_ProductGlossary ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.product.requirement.dao.IProductGlossaryDAO.Id,
                    com.ourteam.product.requirement.dao.IProductGlossaryDAO.EntityName +
                    ".", "RELATED_VHNKKO_ProductGlossary."));
            relatedJoinSQLBuffer.append(" = ").append(RelatedProductGlossaryId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductGlossaryRelate
         * @throws Exception
         */
    public boolean checkIsUnique(ProductGlossaryRelate aProductGlossaryRelate)
        throws Exception {
        if (aProductGlossaryRelate == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductGlossaryRelate.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductGlossaryRelate
     * @throws Exception
     */
    public void insert(ProductGlossaryRelate aProductGlossaryRelate)
        throws Exception {
        super.doInsert(aProductGlossaryRelate);
    }

    /**
         * Batch Insert Datas
         * @param aProductGlossaryRelate
         * @throws Exception
         */
    public void batchInsert(ProductGlossaryRelate[] aProductGlossaryRelates)
        throws Exception {
        super.doBatchInsert(aProductGlossaryRelates);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductGlossaryRelateDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductGlossaryRelate aProductGlossaryRelate)
        throws Exception {
        delete(aProductGlossaryRelate.getId());
    }

    /**
     * Update Data Selective
     * @param aProductGlossaryRelate
     * @throws Exception
     */
    public void update(ProductGlossaryRelate aProductGlossaryRelate)
        throws Exception {
        if (aProductGlossaryRelate.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductGlossaryRelate);

        ProductGlossaryRelate tempObj = findById(aProductGlossaryRelate.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductGlossaryRelate, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductGlossaryRelates[]
     * @throws Exception
     */
    public void batchUpdate(ProductGlossaryRelate[] aProductGlossaryRelates)
        throws Exception {
        super.doBatchUpdate(aProductGlossaryRelates);
    }

    /**
         * Update Data By Condictions
         * @param aProductGlossaryRelate
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductGlossaryRelate aProductGlossaryRelate,
        ProductGlossaryRelateDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aProductGlossaryRelate, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductGlossaryRelateDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(ProductGlossaryRelate aProductGlossaryRelate)
        throws Exception {
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductGlossaryRelate findById(final long id)
        throws Exception {
        ProductGlossaryRelateDAOQueryBean queryBean = new ProductGlossaryRelateDAOQueryBean();

        ProductGlossaryRelateDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductGlossaryRelate[] ProductGlossaryRelates = query(queryBean);

        if (ProductGlossaryRelates.length == 0) {
            return null;
        } else {
            return ProductGlossaryRelates[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductGlossaryRelate[]
         * @throws Exception
         */
    public ProductGlossaryRelate[] query(
        ProductGlossaryRelateDAOQueryBean queryBean) throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductGlossaryRelateRowMapper());

        return (ProductGlossaryRelate[]) result.toArray(new ProductGlossaryRelate[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductGlossaryRelateDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductGlossaryRelateDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(ProductGlossaryRelate[] aProductGlossaryRelates,
        ProductGlossaryRelateDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aProductGlossaryRelates, queryBean);
    }

    public void synchronize(ProductGlossaryRelate[] aProductGlossaryRelates,
        ProductGlossaryRelateDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductGlossaryRelate> callBack)
        throws Exception {
        daoHelper.synchronize(aProductGlossaryRelates, queryBean, callBack);
    }

    public static class JdbcProductGlossaryRelateRowMapper implements RowMapper<ProductGlossaryRelate> {
        public ProductGlossaryRelate mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductGlossaryRelate object = new ProductGlossaryRelate();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object productDefineId = null;

                productDefineId = resultSet.getObject(columnIndex++);

                object.setProductDefineIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (productDefineId != null) {
                    setBeanValue(object, _DataObjectProperty.ProductDefineId,
                        productDefineId);
                }

                Object productGlossaryId = null;

                productGlossaryId = resultSet.getObject(columnIndex++);

                object.setProductGlossaryIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (productGlossaryId != null) {
                    setBeanValue(object, _DataObjectProperty.ProductGlossaryId,
                        productGlossaryId);
                }

                Object relatedProductGlossaryId = null;

                relatedProductGlossaryId = resultSet.getObject(columnIndex++);

                object.setRelatedProductGlossaryIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (relatedProductGlossaryId != null) {
                    setBeanValue(object,
                        _DataObjectProperty.RelatedProductGlossaryId,
                        relatedProductGlossaryId);
                }

                Object relatedType = null;

                relatedType = resultSet.getObject(columnIndex++);

                object.setRelatedTypeNull(resultSet.getBoolean(columnIndex++));

                if (relatedType != null) {
                    setBeanValue(object, _DataObjectProperty.RelatedType,
                        relatedType);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object relatedName = null;

                relatedName = resultSet.getObject(columnIndex++);

                object.setRelatedNameNull(resultSet.getBoolean(columnIndex++));

                if (relatedName != null) {
                    setBeanValue(object, _DataObjectProperty.RelatedName,
                        relatedName);
                }

                Object relatedGlossaryCode = null;

                relatedGlossaryCode = resultSet.getObject(columnIndex++);

                object.setRelatedGlossaryCodeNull(resultSet.getBoolean(
                        columnIndex++));

                if (relatedGlossaryCode != null) {
                    setBeanValue(object,
                        _DataObjectProperty.RelatedGlossaryCode,
                        relatedGlossaryCode);
                }

                Object relatedGlossaryName = null;

                relatedGlossaryName = resultSet.getObject(columnIndex++);

                object.setRelatedGlossaryNameNull(resultSet.getBoolean(
                        columnIndex++));

                if (relatedGlossaryName != null) {
                    setBeanValue(object,
                        _DataObjectProperty.RelatedGlossaryName,
                        relatedGlossaryName);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
